package org.aiforum.backend.service;

import java.util.List;

import javax.transaction.Transactional;
import javax.transaction.Transactional.TxType;

import org.aiforum.backend.common.QueryPreperty;
import org.aiforum.backend.common.Response;
import org.aiforum.backend.mapper.ReplyMapper;
import org.aiforum.domain.Reply;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.util.StringUtil;
/**
 * 回帖业务实现
 * @author Administrator
 *
 */
@Service("replyService")
@Transactional(TxType.REQUIRED)
public class ReplyServiceImpl  implements ReplyService {
   
	@Autowired
	private ReplyMapper replyMapper;
	@Override
	public Reply find(int replyId) {
		Reply reply=replyMapper.findById(replyId);
		return reply;
	}

	@Override
	public Response delete(int replyId) {
		replyMapper.delete(replyId);
		Response response=Response.getInstaner();
		response.setState(true);
		response.setMessage("Delete success");
		return response;
	}

	@Override
	public List<Reply> queryByPreperty(QueryPreperty queryPreperty) {
		//如果查询的属性值不为NULL或""
		if(StringUtil.isNotEmpty(queryPreperty.getQueryValue().toString())){
			//构建模糊查询条件
			String value="%"+queryPreperty.getQueryValue()+"%";
			queryPreperty.setQueryValue(value);
		}else{
			//否则设置为空
			queryPreperty.setQueryValue(null);
		}
		return replyMapper.queryByPreperty(queryPreperty);
	}

}
